﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour
{

    private void Awake()
    {
        var rc =  GetComponent<ReferenceCollector>();
        var item = rc.Get<GameObject>("item");
        var icon = rc.Get<GameObject>("icon");
        var target= rc.Get<GameObject>("target");

        var scrollRect = GetComponent<ScrollRect>();

        bool isDrag=false;
        for(int i=0;i<20;i++)
        {
            var go = GameObject.Instantiate(item);

            var el = EventListener.Get(go);
            el.onBeginDrag = e => {
                if (isDrag) return;
                scrollRect.OnBeginDrag(e);
            };

            el.onDrag = e => {
                if (isDrag) return;
                scrollRect.OnDrag(e);
            };

            el.onEndDrag = e => {
                if (isDrag) return;
                scrollRect.OnEndDrag(e);
            };

            el.onInitializePotentialDrag = e => {
                isDrag = true;
            };

            go.transform.SetParent(item.transform.parent, false);
            go.SetActive(true);
        }
    }
}
